cdef extern from 'SDL.h':
    ctypedef struct SDL_Surface:
        pass

cdef extern from 'pygame/pygame.h':
    SDL_Surface* PySurface_AsSurface (object surface)

cdef extern from 'SDL_svg.h':
    ctypedef struct SDL_svg_context:
        pass
    
    SDL_svg_context *SVG_Load (char *FileName)
    SDL_svg_context *SVG_LoadBuffer (char *data, int len)
    int SVG_SetOffset (SDL_svg_context *Source, double aOffsetX, double aOffsetY)
    int SVG_SetScale (SDL_svg_context *Source, double aScaleX,  double aScaleY)
    int SVG_RenderToSurface (SDL_svg_context *Source, int X, int Y, SDL_Surface* Target)
    void SVG_Free (SDL_svg_context *Source)
    void SVG_Set_Flags (SDL_svg_context *c, unsigned long flags)

    SDL_svg_context *create_SDL_svg_context ()
    void destroy_SDL_svg_context (SDL_svg_context *c)

    float SVG_Width (SDL_svg_context *c)
    float SVG_Height (SDL_svg_context *c)
    int SVG_Version ()
    void SVG_SetClipping (SDL_svg_context *c, int minx, int miny, int maxx, int maxy)

def version ():
    return SVG_Version ()

cdef class Context:
    cdef SDL_svg_context* thisptr
    
    def __cinit__ (self, filename):
        self.thisptr = SVG_Load (filename)
    
    def __dealloc__ (self):
        SVG_Free (self.thisptr)
    
    property width:
        def __get__ (self):
            return SVG_Width (self.thisptr)
    
    property height:
        def __get__ (self):
            return SVG_Height (self.thisptr)
    
    def set_offset (self, x, y):
        SVG_SetOffset (self.thisptr, x, y)
    
    def set_scale (self, x, y):
        SVG_SetScale (self.thisptr, x, y)
    
    def to_surface (self, x, y, surface):
        SVG_RenderToSurface (self.thisptr, x, y, PySurface_AsSurface (surface))
    
    def set_clipping (self, minx, miny, maxx, maxy):
        SVG_SetClipping (self.thisptr, minx, miny, maxx, maxy)
